package com.ymt.bpm.engine.listener;

import org.activiti.engine.RuntimeService;
import org.activiti.engine.delegate.event.ActivitiEventType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Created by Johnny on 2016/12/24.
 */
@Component
public class EventRegister {

    /**
     * Logger
     */
    private Logger logger = LoggerFactory.getLogger(this.getClass());
    /**
     * Activiti RuntimeService bean
     */
    @Autowired
    private RuntimeService runtimeService;
    /**
     * ActivityEventListener
     */
    @Autowired
    private ActivityEventListener activityEventListener;

    /**
     * register all events required
     */
    public void registerEvents() {
        logger.debug("ActivityEventListener registered for ActivitiEventType.ACTIVITY_STARTED");
        runtimeService.addEventListener(activityEventListener, ActivitiEventType.ACTIVITY_STARTED);
        logger.debug("ActivityEventListener registered for ActivitiEventType.ACTIVITY_COMPLETED");
        runtimeService.addEventListener(activityEventListener, ActivitiEventType.ACTIVITY_COMPLETED);
        logger.debug("ActivityEventListener registered for ActivitiEventType.SEQUENCEFLOW_TAKEN");
        runtimeService.addEventListener(activityEventListener, ActivitiEventType.SEQUENCEFLOW_TAKEN);
    }

}
